import { Component, OnInit, Inject } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ActivatedRoute} from '@angular/router';
import { WorkitemModule } from '../../../../../../service/delivent/workItemModule';
import { BranchModule} from '../../../../../../service/delivent/brachModule';
import * as _ from 'lodash';
import * as moment from 'moment';

@Component({
  selector: 'app-delaylist',
  templateUrl: './delaylist.component.html',
   styleUrls: ['./delaylist.component.less']
})
export class DelaylistComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        public activatedRoute: ActivatedRoute,
        private nznot: NzNotificationService,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,

    ) { }
    workGuid:any;
 role:any;
     ngOnInit() {
        this.role = this.tokenService.get().role;
        this.workGuid = this.activatedRoute.snapshot.params.id; // 拿到父组件传过来的操作员的guid来进行操作
        this.getData();
    }
    revertListModal = false;
     revertListData = [];
     isrevertPagination = true;
     revertListHeaderDate =  [  // 配置表头内容
        { label: '操作人', value: 'applyPerson', isclick: false },
        { label: '状态', value: 'repealStatus', isclick: false },
        { label: '环境', value: 'profiles', isclick: false },    
        { label: '撤销时间', value: 'repealTime', isclick: false },
        { label: '撤销理由', value: 'repealDesc', isclick: false },
    
    ];
    listloading = false;
    getData(){
     let url = '/sWorkitem/'+this.workGuid+'/RepealAll';
      this.listloading = true;
        this.utilityService.getData(appConfig.testUrl  + url)
            .subscribe(
                (val) => {
                    this.listloading = false;
                 
                    val.result.forEach(element => {
                        element.buttonData = [
                           {key: 'detail', value: '详细'},
                    
                        ]
                       element.repealTime = moment(element.repealTime ).format('YYYY-MM-DD HH:mm:ss');
                       element.profiles = element.guidProfiles.target
                 });
                  
                    this.revertListData = val.result
                      console.log(   this.revertListData )
                },(error)=>{
                        this.listloading = false;
                     this.nznot.create('error', error.code , error.msg);
                })
    }
    selectedRow(event){

    }
    id:number;
    checkModalData = [];
    delaysModal = false;
     buttonEvent(event) {
       this.id = event.guid;
        if(event.names.key === 'detail') {
     
         this.listloading = true;
            
            this.utilityService.getData(appConfig.testUrl  + '/sRepeal/'+this.id+'/repealListDetail')
               .subscribe(
                (val) => {
                    
                  this.checkModalData = val.result;
                  this.listloading = false;
                  this.delaysModal = true;
                },(error)=>{
                  this.listloading = false;
                  this.nznot.create('error', error.code , error.msg);
                })
        }else   if(event.names.key === 'again') {
            let obj = {
                "deliveryTime": "2018-10-10T16:24:51.778Z",
                "guidRepeal": 0,
                "guidRepealLists": [
                    0
                ],
                "packTiming": "string"
                }
    this.utilityService.postData(appConfig.testUrl+'/sRepeal/againDelivery',obj)
            .subscribe(
            (val) => {
                
            },
            (error)=>{
                  this.listloading = false;
                  this.nznot.create('error', error.code , error.msg);
                })
        }
     }
}